package com.cncf.service.impl;

import com.cncf.dao.SecondReportViewMapper;
import com.cncf.entity.SecondReportView;
import com.cncf.entity.SecondReportViewExample;
import com.cncf.entity.SecondReportView;
import com.cncf.response.ResponseData;
import com.cncf.service.SecondReportViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zj
 */
@Service
public class SecondReportViewServiceImpl implements SecondReportViewService {
    @Autowired
    private SecondReportViewMapper secondReportViewMapper;

    @Override
    public ResponseData<SecondReportView> selectById(String id) {
        ResponseData<SecondReportView> responseData = new ResponseData<>();
        SecondReportViewExample secondReportViewExample = new SecondReportViewExample();
        SecondReportViewExample.Criteria criteria = secondReportViewExample.createCriteria();
        criteria.andIdEqualTo(id);
        List<SecondReportView> list = secondReportViewMapper.selectByExample(secondReportViewExample);
        if (list.size()==0){
            responseData.jsonFill(2,"无效的id",null);
            return responseData;
        }
        SecondReportView secondReportView = list.get(0);
        responseData.jsonFill(1,null,secondReportView);
        responseData.setCount(list.size());
        return responseData;
    }

    @Override
    public ResponseData<List<SecondReportView>> selectByProductUnit(String productUnit) {
        SecondReportViewExample secondReportViewExample = new SecondReportViewExample();
        SecondReportViewExample.Criteria criteria = secondReportViewExample.createCriteria();
        criteria.andEnterpriseNameEqualTo(productUnit);
        List<SecondReportView> list = secondReportViewMapper.selectByExample(secondReportViewExample);
        ResponseData<List<SecondReportView>> responseData = new ResponseData<>();
        if (list.size()==0){
            responseData.jsonFill(2,"无效的生产单位名称（customerName）",null);
            return responseData;
        }
        responseData.jsonFill(1,null,list);
        responseData.setCount(list.size());
        return responseData;
    }
}
